#include "insertprofilethread.h"
#include "../constantapp.h"
#include "../accountmanager.h"
#include "../sqlite/friendprofiletable.h"
#include "../sqlite/sqlitemanager.h"

#include <QDebug>

InsertProfileThread::InsertProfileThread(QObject *parent) :
    QThread(parent)
{
}

void InsertProfileThread::insertFriendProfile(UserProfile* friendProfile) {
    sync.lock();
    m_queueFriendProfile.insert(0, friendProfile);
    sync.unlock();
    condition.wakeAll();
}

void InsertProfileThread::run()
{
    while (m_queueFriendProfile.length() != 0) {
        sync.lock();

        UserProfile* friendProfile = m_queueFriendProfile.last();
        m_queueFriendProfile.removeLast();

        Sqlite::FriendProfileTable::addFriendProfile(friendProfile);
        Sqlite::FriendProfileTable::addFriendProfileFTS(friendProfile);

        sync.unlock();
    }
}

